const db = require('../../db');

exports.addUserInfo = (req, res) => {
    const q = "INSERT INTO `module1_userinfo` (user_id,user_name,bank_id) values(?,?,?) ;";
    const values = [Number(req.params.user_id), req.params.user_name, Number(req.params.bank_id)];

    db.query(q, values, (err, results) => {
        if (err) {
            console.error("插入失败" + err.message);
        }
        else {
            res.send({
                status: 0,
                message: '插入成功！',
                data: results,
            })
        }
    });
}

exports.searchUserInfo = (req, res) => {
    const q = "SELECT * FROM module1_userinfo where user_id = ? ;"
    const values = [req.params.user_id];

    db.query(q, values,(err, results) => {
        if (err) return(err.message)
        res.send({
            status: 0,
            message: '数据返回成功！',
            data: results,
        })
    });
}

exports.updateUserInfo = (req, res) => {
    const q = "UPDATE module1_userinfo SET is_verify = ? where user_id = ? ;"
    const values = [req.params.is_verify,req.params.user_id];

    db.query(q, values, (err, results) => {
        if (err) {
            res.send({
                status: 0,
                message: '更新失败！',
                data: results
            })
        }
        else {
            res.send({
                status: 0,
                message: '更新成功！',
                data: results
            })
        }
    });
}